package cn.edu.jxau.test;

/**
 * 有向边
 * @author 付大石
 *
 */
public class DirectedEdge implements Comparable<DirectedEdge> {

    private final int from;
    private final int to;
    private final double weight;

    public DirectedEdge(int from, int to, double weight) {

        this.from = from;
        this.to = to;
        this.weight = weight;
    }

    public int from() {
        return from;
    }

    public int to() {
        return to;
    }

    public double weight() {
        return weight;
    }

    @Override
    public int compareTo(DirectedEdge edge) {

        double cmp = weight - edge.weight;
        if (cmp < 0) {
            return -1;
        } else if (cmp > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return "DirectedEdge [from=" + from + ", to=" + to + ", weight=" + weight + "]";
    }
}
